package com.zxy.base.util;

import cn.hutool.core.util.IdcardUtil;
import cn.hutool.core.util.PhoneUtil;
import com.zxy.base.BusinessException;
import com.zxy.employee.entity.EmployeeEntity;
import org.springframework.lang.Nullable;

import java.util.function.Predicate;

public class ValidateUtil {


    public static void validateIdCard(String idCard) {
        if(!IdcardUtil.isValidCard(idCard)) {
            throw new BusinessException("身份证不合法");
        }
    }

    public static void validatePhone(String phone) {
        if(PhoneUtil.isPhone(phone)) {
            throw new BusinessException("联系电话不合法");
        }
    }

    public static void validateEmployee(EmployeeEntity employeeEntity) {
        //校验逻辑
    }

    public static <T> void isValid(@Nullable T object, Predicate<T> predicate, String message) {
        if (!predicate.test(object)) {
            throw new BusinessException(message);
        }
    }
}
